﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ASCII.Common;
using System.Windows.Threading;
using PlayDeezGames.Common;

namespace ASCII.ClickTheYellowBox
{
    public enum CTYBState
    {
        None,
        Splash,
        Title,
        Instructions,
        About,
        Play,
        GameOver
    }
    public class CTYBStateMachine:StateMachine<CTYBState>
    {
        private ASCIIRenderer renderer;
        public CTYBStateMachine(ASCIIRenderer theRenderer):base(null,CTYBState.Splash)
        {
            renderer = theRenderer;
            this[CTYBState.Splash] = new CTYBSplashState(renderer);
            this[CTYBState.Title] = new CTYBTitleState(renderer);
            this[CTYBState.Instructions] = new CTYBInstructionsState(renderer);
            this[CTYBState.About] = new CTYBAboutState(renderer);
            this[CTYBState.Play] = new CTYBPlayState(renderer);
            this[CTYBState.GameOver] = new CTYBGameOverState(renderer);

            OnMessage(new MessageBase(StateMachine<CTYBState>.MSGID_Step));//once to load in the splash state
            OnMessage(new MessageBase(StateMachine<CTYBState>.MSGID_Step));//once to draw it
        }
        public override bool OnMessage(MessageBase theMessage)
        {
            if (theMessage.MessageId == StateMachine<CTYBState>.MSGID_Step)
            {
                base.OnMessage(theMessage);
                if (CurrentState != null)
                {
                    CurrentState.Broadcast(new MessageBase(MSGID_Draw), false);
                }
                return true;
            }
            else if (theMessage.MessageId == MSGID_MouseDown || theMessage.MessageId == MSGID_MouseUp)
            {
                MessageWithPayload<MouseButtonEventArgs> m = (theMessage as MessageWithPayload<MouseButtonEventArgs>);
                return false;
            }
            else if (theMessage.MessageId == MSGID_MouseMove)
            {
                return false;
            }
            else
            {
                return base.OnMessage(theMessage);
            }
        }
        protected override int CompareStateId(CTYBState first, CTYBState second)
        {
            return (int)first - (int)second;
        }

        public static void MSGID_KeyDown() { }
        public static void MSGID_KeyUp() { }
        public static void MSGID_MouseDown() { }
        public static void MSGID_MouseUp() { }
        public static void MSGID_MouseMove() { }
        public static void MSGID_Timer() { }
        public static void MSGID_Draw() { }
    }
}
